from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-03-22 14:05:51.674300
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 22, Mar, 2021
Time: 14:05:55
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.0639
Nobs: 238.000 HQIC: -47.8477
Log likelihood: 2807.49 FPE: 9.78066e-22
AIC: -48.3769 Det(Omega_mle): 6.75298e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.465031 0.131080 3.548 0.000
L1.Burgenland 0.065864 0.066071 0.997 0.319
L1.Kärnten -0.205689 0.056022 -3.672 0.000
L1.Niederösterreich 0.141724 0.147748 0.959 0.337
L1.Oberösterreich 0.261106 0.133435 1.957 0.050
L1.Salzburg 0.210313 0.071696 2.933 0.003
L1.Steiermark 0.106733 0.095472 1.118 0.264
L1.Tirol 0.106006 0.064028 1.656 0.098
L1.Vorarlberg -0.001972 0.059130 -0.033 0.973
L1.Wien -0.135338 0.122103 -1.108 0.268
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.471758 0.155394 3.036 0.002
L1.Burgenland 0.017616 0.078326 0.225 0.822
L1.Kärnten 0.348321 0.066414 5.245 0.000
L1.Niederösterreich 0.086782 0.175153 0.495 0.620
L1.Oberösterreich -0.098802 0.158186 -0.625 0.532
L1.Salzburg 0.187810 0.084995 2.210 0.027
L1.Steiermark 0.192043 0.113181 1.697 0.090
L1.Tirol 0.130574 0.075905 1.720 0.085
L1.Vorarlberg 0.157289 0.070097 2.244 0.025
L1.Wien -0.480529 0.144751 -3.320 0.001
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.310310 0.061340 5.059 0.000
L1.Burgenland 0.088766 0.030919 2.871 0.004
L1.Kärnten -0.019964 0.026216 -0.762 0.446
L1.Niederösterreich 0.056893 0.069140 0.823 0.411
L1.Oberösterreich 0.306980 0.062442 4.916 0.000
L1.Salzburg 0.013154 0.033551 0.392 0.695
L1.Steiermark -0.008149 0.044677 -0.182 0.855
L1.Tirol 0.068191 0.029963 2.276 0.023
L1.Vorarlberg 0.101341 0.027670 3.662 0.000
L1.Wien 0.089100 0.057139 1.559 0.119
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.218941 0.065179 3.359 0.001
L1.Burgenland 0.001064 0.032854 0.032 0.974
L1.Kärnten 0.015015 0.027857 0.539 0.590
L1.Niederösterreich 0.037654 0.073468 0.513 0.608
L1.Oberösterreich 0.393499 0.066351 5.931 0.000
L1.Salzburg 0.082202 0.035651 2.306 0.021
L1.Steiermark 0.174421 0.047473 3.674 0.000
L1.Tirol 0.043900 0.031838 1.379 0.168
L1.Vorarlberg 0.079960 0.029402 2.720 0.007
L1.Wien -0.046531 0.060715 -0.766 0.443
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.516561 0.128629 4.016 0.000
L1.Burgenland 0.061770 0.064836 0.953 0.341
L1.Kärnten 0.005696 0.054975 0.104 0.917
L1.Niederösterreich -0.033098 0.144986 -0.228 0.819
L1.Oberösterreich 0.151538 0.130941 1.157 0.247
L1.Salzburg 0.069795 0.070356 0.992 0.321
L1.Steiermark 0.097270 0.093687 1.038 0.299
L1.Tirol 0.218914 0.062831 3.484 0.000
L1.Vorarlberg 0.028053 0.058024 0.483 0.629
L1.Wien -0.105989 0.119820 -0.885 0.376
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187683 0.095079 1.974 0.048
L1.Burgenland -0.023005 0.047925 -0.480 0.631
L1.Kärnten -0.012496 0.040636 -0.308 0.758
L1.Niederösterreich 0.003717 0.107169 0.035 0.972
L1.Oberösterreich 0.416071 0.096788 4.299 0.000
L1.Salzburg 0.007805 0.052005 0.150 0.881
L1.Steiermark -0.015702 0.069251 -0.227 0.821
L1.Tirol 0.167577 0.046443 3.608 0.000
L1.Vorarlberg 0.049488 0.042890 1.154 0.249
L1.Wien 0.224753 0.088567 2.538 0.011
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.250801 0.122981 2.039 0.041
L1.Burgenland 0.020479 0.061989 0.330 0.741
L1.Kärnten -0.049610 0.052561 -0.944 0.345
L1.Niederösterreich -0.053636 0.138619 -0.387 0.699
L1.Oberösterreich -0.027557 0.125191 -0.220 0.826
L1.Salzburg 0.077256 0.067266 1.149 0.251
L1.Steiermark 0.367603 0.089573 4.104 0.000
L1.Tirol 0.451088 0.060072 7.509 0.000
L1.Vorarlberg 0.155784 0.055476 2.808 0.005
L1.Wien -0.187239 0.114558 -1.634 0.102
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126559 0.143979 0.879 0.379
L1.Burgenland 0.028607 0.072573 0.394 0.693
L1.Kärnten -0.060160 0.061535 -0.978 0.328
L1.Niederösterreich 0.205693 0.162288 1.267 0.205
L1.Oberösterreich -0.023222 0.146567 -0.158 0.874
L1.Salzburg 0.246278 0.078752 3.127 0.002
L1.Steiermark 0.137242 0.104867 1.309 0.191
L1.Tirol 0.040653 0.070329 0.578 0.563
L1.Vorarlberg 0.073561 0.064948 1.133 0.257
L1.Wien 0.225935 0.134119 1.685 0.092
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.578737 0.078405 7.381 0.000
L1.Burgenland -0.032943 0.039520 -0.834 0.405
L1.Kärnten -0.019995 0.033510 -0.597 0.551
L1.Niederösterreich 0.017288 0.088375 0.196 0.845
L1.Oberösterreich 0.313461 0.079814 3.927 0.000
L1.Salzburg 0.013308 0.042885 0.310 0.756
L1.Steiermark -0.017490 0.057106 -0.306 0.759
L1.Tirol 0.085693 0.038298 2.238 0.025
L1.Vorarlberg 0.113050 0.035368 3.196 0.001
L1.Wien -0.042523 0.073036 -0.582 0.560
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.134043 0.049042 0.184870 0.238204 0.065825 0.134608 -0.028551 0.159083
Kärnten 0.134043 1.000000 0.007568 0.193989 0.168036 -0.102961 0.144601 0.018067 0.304023
Niederösterreich 0.049042 0.007568 1.000000 0.259131 0.062559 0.266855 0.161417 0.052750 0.309050
Oberösterreich 0.184870 0.193989 0.259131 1.000000 0.288984 0.262854 0.086449 0.068572 0.140272
Salzburg 0.238204 0.168036 0.062559 0.288984 1.000000 0.119750 0.068590 0.087330 -0.004197
Steiermark 0.065825 -0.102961 0.266855 0.262854 0.119750 1.000000 0.121175 0.116838 -0.123507
Tirol 0.134608 0.144601 0.161417 0.086449 0.068590 0.121175 1.000000 0.166996 0.147909
Vorarlberg -0.028551 0.018067 0.052750 0.068572 0.087330 0.116838 0.166996 1.000000 0.020434
Wien 0.159083 0.304023 0.309050 0.140272 -0.004197 -0.123507 0.147909 0.020434 1.000000